# -*- coding: utf-8 -*-

from odoo import models, fields, api


class CpqUom(models.Model):
    _name = 'cpq.uom'
    _description = '单位'
    _rec_name = 'name'
    _order = 'name'

    name = fields.Char('单位名称', required=True, index=True, help='如：件、个、套')
    code = fields.Char('单位代码', required=True, index=True, help='如：PCS、SET、KG')
    symbol = fields.Char('单位符号', help='如：件、个、kg')
    
    # 单位类型
    uom_type = fields.Selection([
        ('unit', '数量单位'),
        ('weight', '重量单位'),
        ('length', '长度单位'),
        ('area', '面积单位'),
        ('volume', '体积单位'),
        ('other', '其他')
    ], string='单位类型', default='unit')
    
    active = fields.Boolean('有效', default=True)
    notes = fields.Text('备注')
    
    def name_get(self):
        result = []
        for record in self:
            name = f'{record.name} ({record.code})'
            result.append((record.id, name))
        return result

